﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Text;

namespace WEALTH
{
    public partial class CustomerListView : System.Web.UI.Page
    {
        public string strLeftmenu = string.Empty;
        ExcuteDao dao = new ExcuteDao();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (!string.IsNullOrEmpty(Request.QueryString["listviewid"]) &&
                          !string.IsNullOrEmpty(Request.QueryString["menutype"]))
                {
                    SetLeftMenu();
                    loaderData(Convert.ToInt32(Request.QueryString["listviewid"]));
                }
            }
        }

        public string GetBuyDivStr(object isCanBuy, object listCount, object listId)
        {
            bool isCB = (Boolean)isCanBuy;
            StringBuilder str = new StringBuilder();

            if (isCB)
            {
                str.Append("<table><tr>");
                str.Append("<td>需要积分：<strong class=\"tb-rmb-num\">" + listCount.ToString() + "</strong></td>");
                str.Append("<td><a href=ListView.aspx?listviewid=" + listId.ToString() + "&menutype=" + string.IsNullOrEmpty(Request.QueryString["menutype"]) + "&isGift=1><img src=\"images/buy.jpg\"></a></td>");


                //str.Append("<td><a href=\"ListView.aspx?listviewid="
                //        + listId.ToString() + "&menutype=" + string.IsNullOrEmpty(Request.QueryString["menutype"]) + "&isGift=1" + "\"><img src=images/buy.jpg /></a></td>");
                str.Append("</tr></table>");
            }
            return str.ToString();
        }

        //=============================================
        //函数名称:loaderData()
        //作    用:将查询到的内容绑定到控件上
        //=============================================
        private void loaderData(int listid)
        {
            DataTable dt = new DataTable();

            dt = dao.Get_ListText(listid);

            if (dt != null && dt.Rows.Count > 0)
            {
                lblTitle.Text = SpecialCharHandler.HtmlDiscode(dt.Rows[0]["listTitle"].ToString());
                lblDate.Text = dt.Rows[0]["listDate"].ToString();
                lblName.Text = SpecialCharHandler.HtmlDiscode(dt.Rows[0]["listFrom"].ToString());
                lblText.Text = SpecialCharHandler.HtmlDiscode(dt.Rows[0]["listText"].ToString());
            }
        }
        /// <summary>
        /// 设置左侧菜单
        /// </summary>
        private void SetLeftMenu()
        {
            string strmenutype = Request.QueryString["menutype"].ToString();

            DataTable dt = dao.Get_LeftMenuALL("", strmenutype);
            strLeftmenu = string.Empty;
            strLeftmenu += "<li id=\"one\" class=\"files\"><a href=\"#\">" + strmenutype + "</a><ul class=\"sub-menu\">";

            if (dt != null && dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    int intMenuID = Convert.ToInt32(dt.Rows[i]["MenuID"]);
                    string strmenuname = dt.Rows[i]["MenuName"].ToString();
                    DataTable menuDt = dao.Get_ListALL("", "", intMenuID, "");

                    if (menuDt.Rows.Count == 1)
                    {
                        int listid = Convert.ToInt32(menuDt.Rows[0]["listID"]);

                        strLeftmenu += "<li><a href=\"ListView.aspx?listviewid="
                        + listid + "&menutype=" + strmenutype + "\" title=\"\"><em>"
                        + (i + 1).ToString().PadLeft(2, '0') + "</em>" + strmenuname + "</a></li>";
                    }
                    else
                    {
                        strLeftmenu += "<li><a href=\"List.aspx?menuid="
                            + intMenuID + "&menutype=" + strmenutype + "\" title=\"\"><em>"
                            + (i + 1).ToString().PadLeft(2, '0') + "</em>" + strmenuname + "</a></li>";
                    }
                    //strLeftmenu += "<li><a href=\"#\" title=\"\"><em>01</em>企业文化</a></li>";
                    //strLeftmenu += "<li><a href=\"#\" title=\"\"><em>01</em>精英团队</a></li>";
                    //strLeftmenu += "<li><a href=\"#\" title=\"\"><em>01</em>公司新闻</a></li>";
                    //strLeftmenu += "<li><a href=\"#\" title=\"\"><em>01</em>合作伙伴</a></li>";
                    //strLeftmenu += "<li><a href=\"#\" title=\"\"><em>01</em>招贤纳士</a></li>";
                    //strLeftmenu += "<li><a href=\"#\" title=\"\"><em>01</em>联系我们</a></li>";
                }
            }
            strLeftmenu += "</ul></li>";
        }
    }
}